import axios from 'axios'
import BASE from '@/base'

axios.defaults.baseURL = BASE.apiUrl
// 设置请求头
axios.defaults.headers['Accept'] = 'application/json';
axios.defaults.timeout = 2000;



axios.interceptors.request.use(config => {
  // window.console.log('config', config)
  return config
}, error => {
  return Promise.reject(error);

})


axios.interceptors.response.use( res => {
  if(res.status === 200){
    // window.console.log('请求成功1111',res)
    return Promise.resolve(res.data)

  }else{
    window.console.log('请求成功222',res)
    return Promise.resolve(res)
  }
}, error => {
  window.console.log('请求成功3333',error)
  return Promise.reject(error)
})

// const Token = sessionStorage.getItem('token')? sessionStorage.getItem('token') : ''

function ajax(url, type='GET', data) {
 return axios({
    method: type,
    url,
    data: {...data}
  }).then((res) => {
    return Promise.resolve(res)
  }).catch( error => {
    return Promise.reject(error)
  })
}




export default ajax